

#ifndef UD_DBSYMTB_H
#define UD_DBSYMTB_H

#include "zdbmain.h"
#include "zdbdict.h"
#include "zdbdate.h"
#include "zdbbackground.h"
#include "zgevec2d.h"
#include "zacgiviewport.h"
#include "zacgivisualstyle.h"

#pragma pack(push, 8)

#ifdef target
# undef target 
#endif

class UcDbSortentsTable;
class UcDbSymbolTableIterator;
class UcDbSymbolTableRecord;
class UcDbAnnotationScale;
class UcGsView;
class UcString;

class ZSOFT_NO_VTABLE UcDbSymbolTable: public UcDbObject
{
public:
    UCDB_DECLARE_MEMBERS(UcDbSymbolTable);
    UcDbSymbolTable();
    virtual ~UcDbSymbolTable();

    typedef UcDbSymbolTableRecord RecordType;

    Ucad::ErrorStatus getAt (const ZTCHAR* entryName,
                             UcDbSymbolTableRecord*& pRec,
                             UcDb::OpenMode openMode,
                             bool openErasedRec = false) const;
    Ucad::ErrorStatus getAt (const ZTCHAR* entryName,
                             UcDbObjectId& recordId,
                             bool getErasedRecord = false) const;
    bool              has(const ZTCHAR* name) const;
    bool              has(UcDbObjectId id) const;
    Ucad::ErrorStatus newIterator(UcDbSymbolTableIterator*& pIterator,
                                  bool atBeginning = true,
                                  bool skipDeleted = true) const;
    Ucad::ErrorStatus add(UcDbSymbolTableRecord* pRecord);
    Ucad::ErrorStatus add(UcDbObjectId& recordId, UcDbSymbolTableRecord* pRecord);

};

class UcDbBlockTableRecord;
class UcDbBlockTableIterator;

class UcDbBlockTable: public UcDbSymbolTable
{
public:
    UCDB_DECLARE_MEMBERS(UcDbBlockTable);
    UcDbBlockTable();
    virtual ~UcDbBlockTable();

    typedef UcDbBlockTableRecord RecordType;

    Ucad::ErrorStatus getAt (const ZTCHAR* entryName,
                             UcDbBlockTableRecord*& pRec,
                             UcDb::OpenMode openMode,
                             bool openErasedRec = false) const;
    Ucad::ErrorStatus getAt (const ZTCHAR* entryName,
                             UcDbObjectId& recordId,
                             bool getErasedRec = false) const;
    bool              has   (const ZTCHAR* name) const;
    bool              has   (UcDbObjectId id) const;
    Ucad::ErrorStatus newIterator(UcDbBlockTableIterator*& pIterator,
                                  bool atBeginning = true,
                                  bool skipDeleted = true) const;
    Ucad::ErrorStatus add   (UcDbBlockTableRecord* pRecord);
    Ucad::ErrorStatus add   (UcDbObjectId& recordId, UcDbBlockTableRecord* pRecord);

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
};

class UcDbLayerTableRecord;
class UcDbLayerTableIterator;

class UcDbLayerTable: public UcDbSymbolTable
{
public:
    UCDB_DECLARE_MEMBERS(UcDbLayerTable);
    UcDbLayerTable();
    virtual ~UcDbLayerTable();

    typedef UcDbLayerTableRecord RecordType;

    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbLayerTableRecord*& pRec,
                            UcDb::OpenMode openMode,
                            bool openErasedRec = false) const;
    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbObjectId& recordId,
                            bool getErasedRecord = false) const;
    bool              has  (const ZTCHAR* name) const;
    bool              has  (UcDbObjectId id) const;
    Ucad::ErrorStatus newIterator(UcDbLayerTableIterator*& pIterator,
                                  bool atBeginning = true,
                                  bool skipDeleted = true) const;
    Ucad::ErrorStatus add (UcDbLayerTableRecord* pRecord);
    Ucad::ErrorStatus add (UcDbObjectId& recordId, UcDbLayerTableRecord* pRecord);

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;

    void generateUsageData();

    bool hasUnreconciledLayers() const;
    Ucad::ErrorStatus getUnreconciledLayers(UcDbObjectIdArray& idArray) const;
};

class UcDbTextStyleTableRecord;
class UcDbTextStyleTableIterator;

class UcDbTextStyleTable: public UcDbSymbolTable
{
public:
    UCDB_DECLARE_MEMBERS(UcDbTextStyleTable);
    UcDbTextStyleTable();
    virtual ~UcDbTextStyleTable();

    typedef UcDbTextStyleTableRecord RecordType;

    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbTextStyleTableRecord*& pRec,
                            UcDb::OpenMode openMode,
                            bool openErasedRec = false) const;
    Ucad::ErrorStatus getAt (const ZTCHAR* entryName,
                             UcDbObjectId& recordId,
                             bool getErasedRecord = false) const;
    bool              has   (const ZTCHAR* name) const;
    bool              has   (UcDbObjectId id) const;
    Ucad::ErrorStatus newIterator(UcDbTextStyleTableIterator*& pIterator,
                                  bool atBeginning = true,
                                  bool skipDeleted = true) const;
    Ucad::ErrorStatus add   (UcDbTextStyleTableRecord* pRecord);
    Ucad::ErrorStatus add   (UcDbObjectId&  recordId,
        UcDbTextStyleTableRecord* pRecord);

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
};

class UcDbLinetypeTableRecord;
class UcDbLinetypeTableIterator;

class UcDbLinetypeTable: public UcDbSymbolTable
{
public:
    UCDB_DECLARE_MEMBERS(UcDbLinetypeTable);
    UcDbLinetypeTable();
    virtual ~UcDbLinetypeTable();

    typedef UcDbLinetypeTableRecord RecordType;

    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbLinetypeTableRecord*& pRec,
                            UcDb::OpenMode openMode,
                            bool openErasedRec = false) const;
    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbObjectId& recordId,
                            bool getErasedRec = false) const;
    bool              has  (const ZTCHAR* name) const;
    bool              has  (UcDbObjectId id) const;
    Ucad::ErrorStatus newIterator(UcDbLinetypeTableIterator*& pIterator,
                                  bool atBeginning = true,
                                  bool skipDeleted = true) const;
    Ucad::ErrorStatus add  (UcDbLinetypeTableRecord* pRecord);
    Ucad::ErrorStatus add  (UcDbObjectId& recordId,
        UcDbLinetypeTableRecord* pRecord);

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
};

class UcDbAbstractViewTableRecord;
class UcDbAbstractViewTableIterator;

class ZSOFT_NO_VTABLE UcDbAbstractViewTable: public UcDbSymbolTable
{
public:
    UCDB_DECLARE_MEMBERS(UcDbAbstractViewTable);
    UcDbAbstractViewTable();
    virtual ~UcDbAbstractViewTable();
    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbAbstractViewTableRecord*& pRec,
                            UcDb::OpenMode openMode,
                            bool openErasedRec = false) const;
    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbObjectId& recordId,
                            bool getErasedRecord = false) const;
    bool              has  (const ZTCHAR* name) const;
    bool              has  (UcDbObjectId id) const;
    Ucad::ErrorStatus newIterator(UcDbAbstractViewTableIterator*& pIterator,
                                  bool atBeginning = true,
                                  bool skipDeleted = true) const;
    Ucad::ErrorStatus add  (UcDbAbstractViewTableRecord* pRecord);
    Ucad::ErrorStatus add  (UcDbObjectId&  recordId,
        UcDbAbstractViewTableRecord* pRecord);
};

class UcDbViewTableRecord;
class UcDbViewTableIterator;

class UcDbViewTable: public UcDbAbstractViewTable
{
public:
    UCDB_DECLARE_MEMBERS(UcDbViewTable);
    UcDbViewTable();
    virtual ~UcDbViewTable();

    typedef UcDbViewTableRecord RecordType;

    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbViewTableRecord*& pRec,
                            UcDb::OpenMode openMode,
                            bool openErasedRec = false) const;
    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbObjectId& recordId,
                            bool getErasedRec = false) const;
    bool              has  (const ZTCHAR* name) const;
    bool              has  (UcDbObjectId id) const;
    Ucad::ErrorStatus newIterator(UcDbViewTableIterator*& pIterator,
                                  bool atBeginning = true,
                                  bool skipDeleted = true) const;
    Ucad::ErrorStatus add  (UcDbViewTableRecord* pRecord);
    Ucad::ErrorStatus add  (UcDbObjectId&  recordId,
        UcDbViewTableRecord* pRecord);

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
};

class UcDbUCSTableRecord;
class UcDbUCSTableIterator;

class UcDbUCSTable: public UcDbSymbolTable
{
public:
    UCDB_DECLARE_MEMBERS(UcDbUCSTable);
    UcDbUCSTable();
    virtual ~UcDbUCSTable();

    typedef UcDbUCSTableRecord RecordType;

    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbUCSTableRecord*& pRec,
                            UcDb::OpenMode openMode,
                            bool openErasedRec = false) const;
    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbObjectId& recordId,
                            bool getErasedRecord = false) const;
    bool              has  (const ZTCHAR* name) const;
    bool              has  (UcDbObjectId id) const;
    Ucad::ErrorStatus newIterator(UcDbUCSTableIterator*& pIterator,
                                  bool atBeginning = true,
                                  bool skipDeleted = true) const;
    Ucad::ErrorStatus add  (UcDbUCSTableRecord* pRecord);
    Ucad::ErrorStatus add  (UcDbObjectId&  recordId,
        UcDbUCSTableRecord* pRecord);

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
};

class UcDbViewportTableRecord;
class UcDbViewportTableIterator;

class UcDbViewportTable: public UcDbAbstractViewTable
{
public:
    UCDB_DECLARE_MEMBERS(UcDbViewportTable);
    UcDbViewportTable();
    virtual ~UcDbViewportTable();

    typedef UcDbViewportTableRecord RecordType;

    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbViewportTableRecord*& pRec,
                            UcDb::OpenMode openMode,
                            bool openErasedRec = false) const;
    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbObjectId& recordId,
                            bool getErasedRecord = false) const;
    bool              has  (const ZTCHAR* name) const;
    bool              has  (UcDbObjectId id) const;
    Ucad::ErrorStatus newIterator(UcDbViewportTableIterator*& pIterator,
                                  bool atBeginning = true,
                                  bool skipDeleted = true) const;
    Ucad::ErrorStatus add  (UcDbViewportTableRecord* pRecord);
    Ucad::ErrorStatus add  (UcDbObjectId& recordId,
        UcDbViewportTableRecord* pRecord);

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
};

class UcDbRegAppTableRecord;
class UcDbRegAppTableIterator;

class UcDbRegAppTable: public UcDbSymbolTable
{
public:
    UCDB_DECLARE_MEMBERS(UcDbRegAppTable);
    UcDbRegAppTable();
    virtual ~UcDbRegAppTable();

    typedef UcDbRegAppTableRecord RecordType;

    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbRegAppTableRecord*& pRec,
                            UcDb::OpenMode openMode,
                            bool openErasedRec = false) const;
    Ucad::ErrorStatus getAt(const ZTCHAR* entryName,
                            UcDbObjectId& recordId,
                            bool getErasedRec = false) const;
    bool              has  (const ZTCHAR* name) const;
    bool              has  (UcDbObjectId id) const;
    Ucad::ErrorStatus newIterator(UcDbRegAppTableIterator*& pIterator,
                                  bool atBeginning = true,
                                  bool skipDeleted = true) const;
    Ucad::ErrorStatus   add     (UcDbRegAppTableRecord* pRecord);
    Ucad::ErrorStatus   add     (UcDbObjectId&  recordId,
        UcDbRegAppTableRecord* pRecord);

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
};

class UcDbDimStyleTableRecord;
class UcDbDimStyleTableIterator;

class UcDbDimStyleTable: public UcDbSymbolTable
{
public:
    UCDB_DECLARE_MEMBERS(UcDbDimStyleTable);
    UcDbDimStyleTable();
    virtual ~UcDbDimStyleTable();

    typedef UcDbDimStyleTableRecord RecordType;

    Ucad::ErrorStatus   getAt   (const ZTCHAR* entryName,
                                 UcDbDimStyleTableRecord*& pRec,
                                 UcDb::OpenMode openMode,
                                 bool openErasedRec = false) const;
    Ucad::ErrorStatus   getAt   (const ZTCHAR* entryName,
                                 UcDbObjectId& recordId,
                                 bool getErasedRec = false) const;
    bool                has     (const ZTCHAR* name) const;
    bool                has     (UcDbObjectId id) const;
    Ucad::ErrorStatus   newIterator(UcDbDimStyleTableIterator*& pIterator,
                                    bool atBeginning = true,
                                    bool skipDeleted = true) const;
    Ucad::ErrorStatus   add     (UcDbDimStyleTableRecord* pRecord);
    Ucad::ErrorStatus   add     (UcDbObjectId&  recordId,
        UcDbDimStyleTableRecord* pRecord);

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
};

class UcDbSymbolTableIterator
{
public:
    virtual ~UcDbSymbolTableIterator();

    void                start   (bool atBeginning = true,
                                 bool skipDeleted = true);

    bool                done    () const;

    Ucad::ErrorStatus   getRecordId(UcDbObjectId& id) const;

    Ucad::ErrorStatus   getRecord(UcDbSymbolTableRecord*& pRecord,
                                 UcDb::OpenMode openMode,
                                 bool openErasedRec = false) const;

    void                step    (bool forward = true,
                                 bool skipDeleted = true);

    Ucad::ErrorStatus   seek    (UcDbObjectId id);

    Ucad::ErrorStatus   seek    (const UcDbSymbolTableRecord* pRecord);
protected:
    void* mpImp;
    UcDbSymbolTableIterator();
    friend class UcDbSymbolTable;
};

class UcDbBlockTableIterator : public UcDbSymbolTableIterator
{
public:
    Ucad::ErrorStatus getRecord(UcDbBlockTableRecord*& pRecord,
        UcDb::OpenMode openMode, bool openErasedRec = false) const;
    Ucad::ErrorStatus seek(UcDbObjectId id);
    Ucad::ErrorStatus seek(const UcDbBlockTableRecord* pRecord);

protected:
    UcDbBlockTableIterator();
    friend class UcDbBlockTable;
};

class UcDbLayerTableIterator : public UcDbSymbolTableIterator
{
public:
    Ucad::ErrorStatus getRecord(UcDbLayerTableRecord*& pRecord,
        UcDb::OpenMode openMode, bool openErasedRec = false) const;
    Ucad::ErrorStatus seek(UcDbObjectId id);
    Ucad::ErrorStatus seek(const UcDbLayerTableRecord* pRecord);
    bool getSkipHidden() const;
    void setSkipHidden(bool value);
    bool getSkipReconciled() const;
    void setSkipReconciled(bool value);
protected:
    UcDbLayerTableIterator();
    friend class UcDbLayerTable;
};

class UcDbTextStyleTableIterator : public UcDbSymbolTableIterator
{
public:
    Ucad::ErrorStatus getRecord(UcDbTextStyleTableRecord*& pRecord,
        UcDb::OpenMode openMode, bool openErasedRec = false) const;
    Ucad::ErrorStatus seek(UcDbObjectId id);
    Ucad::ErrorStatus seek(const UcDbTextStyleTableRecord* pRecord);

protected:
    UcDbTextStyleTableIterator();
    friend class UcDbTextStyleTable;
};

class UcDbLinetypeTableIterator : public UcDbSymbolTableIterator
{
public:
    Ucad::ErrorStatus getRecord(UcDbLinetypeTableRecord*& pRecord,
        UcDb::OpenMode openMode, bool openErasedRec = false) const;
    Ucad::ErrorStatus seek(UcDbObjectId id);
    Ucad::ErrorStatus seek(const UcDbLinetypeTableRecord* pRecord);

protected:
    UcDbLinetypeTableIterator();
    friend class UcDbLinetypeTable;
};

class UcDbAbstractViewTableIterator : public UcDbSymbolTableIterator
{
public:
    Ucad::ErrorStatus getRecord(UcDbAbstractViewTableRecord*& pRecord,
        UcDb::OpenMode openMode, bool openErasedRec = false) const;
    Ucad::ErrorStatus seek(UcDbObjectId id);
    Ucad::ErrorStatus seek(const UcDbAbstractViewTableRecord* pRecord);

protected:
    UcDbAbstractViewTableIterator();
    friend class UcDbAbstractViewTable;
};

class UcDbViewTableIterator : public UcDbAbstractViewTableIterator
{
public:
    Ucad::ErrorStatus getRecord(UcDbViewTableRecord*& pRecord,
        UcDb::OpenMode openMode, bool openErasedRec = false) const;
    Ucad::ErrorStatus seek(UcDbObjectId id);
    Ucad::ErrorStatus seek(const UcDbViewTableRecord* pRecord);

protected:
    UcDbViewTableIterator();
    friend class UcDbViewTable;
};

class UcDbUCSTableIterator : public UcDbSymbolTableIterator
{
public:
    Ucad::ErrorStatus getRecord(UcDbUCSTableRecord*& pRecord,
        UcDb::OpenMode openMode, bool openErasedRec = false) const;
    Ucad::ErrorStatus seek(UcDbObjectId id);
    Ucad::ErrorStatus seek(const UcDbUCSTableRecord* pRecord);

protected:
    UcDbUCSTableIterator();
    friend class UcDbUCSTable;
};

class UcDbViewportTableIterator : public UcDbAbstractViewTableIterator
{
public:
    Ucad::ErrorStatus getRecord(UcDbViewportTableRecord*& pRecord,
        UcDb::OpenMode openMode, bool openErasedRec = false) const;
    Ucad::ErrorStatus seek(UcDbObjectId id);
    Ucad::ErrorStatus seek(const UcDbViewportTableRecord* pRecord);

protected:
    UcDbViewportTableIterator();
    friend class UcDbViewportTable;
};

class UcDbRegAppTableIterator : public UcDbSymbolTableIterator
{
public:
    Ucad::ErrorStatus getRecord(UcDbRegAppTableRecord*& pRecord,
        UcDb::OpenMode openMode, bool openErasedRec = false) const;
    Ucad::ErrorStatus seek(UcDbObjectId id);
    Ucad::ErrorStatus seek(const UcDbRegAppTableRecord* pRecord);

protected:
    UcDbRegAppTableIterator();
    friend class UcDbRegAppTable;
};

class UcDbDimStyleTableIterator : public UcDbSymbolTableIterator
{
public:
    Ucad::ErrorStatus getRecord(UcDbDimStyleTableRecord*& pRecord,
        UcDb::OpenMode openMode, bool openErasedRec = false) const;
    Ucad::ErrorStatus seek(UcDbObjectId id);
    Ucad::ErrorStatus seek(const UcDbDimStyleTableRecord* pRecord);

protected:
    UcDbDimStyleTableIterator();
    friend class UcDbDimStyleTable;
};

class ZSOFT_NO_VTABLE UcDbSymbolTableRecord: public  UcDbObject
{
public:
    UCDB_DECLARE_MEMBERS(UcDbSymbolTableRecord);
    UcDbSymbolTableRecord();
    virtual ~UcDbSymbolTableRecord();

    typedef UcDbSymbolTable TableType;

    Ucad::ErrorStatus getName(ZTCHAR*& pName) const;
    Ucad::ErrorStatus getName(UcString & sName) const;
    Ucad::ErrorStatus getName(const ZTCHAR*& pName) const;
    Ucad::ErrorStatus setName(const ZTCHAR* pName);

    bool isDependent() const;

    bool isResolved() const;
};

class UcDbBlockTableRecordIterator
{
public:
    virtual ~UcDbBlockTableRecordIterator();

    void              start (bool atBeginning = true,
                             bool skipDeleted = true);

    bool              done  () const;

    Ucad::ErrorStatus getEntityId (UcDbObjectId& entityId) const;

    Ucad::ErrorStatus getEntity(UcDbEntity*& pEntity, UcDb::OpenMode openMode,
                                bool openErasedEntity = false) const;

    UcDbBlockTableRecord* blockTableRecord() const;

    void              step (bool forward = true,
                            bool skipDeleted = true);

    Ucad::ErrorStatus seek (UcDbObjectId id);

    Ucad::ErrorStatus seek (const UcDbEntity* pEntity);

protected:
    class UcDbImpBlockTableRecordIterator * mpImp;
private:
    UcDbBlockTableRecordIterator();
	friend class UcDbImpBlockTableRecord;
};

class UcDbBlockReferenceIdIterator
{
public:
    ~UcDbBlockReferenceIdIterator();

    void              start () { mPos = 0; }
        
    bool              done  () const { return mPos >= mAry.length(); }

    Ucad::ErrorStatus getBlockReferenceId (UcDbObjectId& id) const;

    Ucad::ErrorStatus getDatabase (UcDbDatabase*& pDb) const;

    Ucad::ErrorStatus getBlockReference(UcDbBlockReference*& pBlkRef,
                        UcDb::OpenMode openMode, bool openErasedEntity = false) const;

    void              step () { mPos++; }

    Ucad::ErrorStatus seek (UcDbObjectId id);

private:
    UcDbBlockReferenceIdIterator();
    friend class UcDbBlockTableRecord;

    int               mPos;
    UcDbObjectIdArray mAry;
};

class UcDbBlockTableRecord: public  UcDbSymbolTableRecord
{
public:
    UCDB_DECLARE_MEMBERS(UcDbBlockTableRecord);

    UcDbBlockTableRecord();
    virtual ~UcDbBlockTableRecord();

    typedef UcDbBlockTable TableType;
    typedef UcArray<ZSoft::UInt8> PreviewIcon;

    virtual Ucad::ErrorStatus dwgOutFields(UcDbDwgFiler* filer) const;
    virtual Ucad::ErrorStatus dxfOutFields(UcDbDxfFiler* filer) const;

    Ucad::ErrorStatus appendUcDbEntity(UcDbEntity* pEntity);

    Ucad::ErrorStatus appendUcDbEntity(UcDbObjectId& pOutputId,
        UcDbEntity* pEntity);

    Ucad::ErrorStatus newIterator(
        UcDbBlockTableRecordIterator*& pIterator,
        bool atBeginning = true,
        bool skipDeleted = true) const;

    Ucad::ErrorStatus comments(ZTCHAR*& pString) const;
    Ucad::ErrorStatus comments(const ZTCHAR*& pString) const;
    Ucad::ErrorStatus setComments(const ZTCHAR* pString);

    Ucad::ErrorStatus pathName(ZTCHAR*& pPath) const;
    Ucad::ErrorStatus pathName(const ZTCHAR*& pPath) const;
    Ucad::ErrorStatus setPathName(const ZTCHAR* pathStr);
 
    UcGePoint3d       origin() const;
    Ucad::ErrorStatus setOrigin(const UcGePoint3d& pt);

    Ucad::ErrorStatus openBlockBegin(UcDbBlockBegin*& pBlockBegin,
                                     UcDb::OpenMode   openMode);
 
    Ucad::ErrorStatus openBlockEnd(UcDbBlockEnd*& pBlockEnd,
                                   UcDb::OpenMode openMode);

    bool              hasAttributeDefinitions() const;

    bool              hasPreviewIcon() const;
    Ucad::ErrorStatus getPreviewIcon(PreviewIcon &previewIcon) const;
    Ucad::ErrorStatus setPreviewIcon(const PreviewIcon &previewIcon);

    bool              isAnonymous() const;

    bool              isFromExternalReference() const;

    bool              isFromOverlayReference() const;

    bool              isLayout() const;

    UcDbObjectId      getLayoutId() const;
    Ucad::ErrorStatus setLayoutId(UcDbObjectId);

    Ucad::ErrorStatus newBlockReferenceIdIterator(
        UcDbBlockReferenceIdIterator*& pIter) const;

    Ucad::ErrorStatus getBlockReferenceIds(UcDbObjectIdArray& ids,
                                           bool bDirectOnly = true,
                                           bool bForceValidity = false) const;

    Ucad::ErrorStatus getErasedBlockReferenceIds(UcDbObjectIdArray&);

    Ucad::ErrorStatus
    getSortentsTable(UcDbSortentsTable*& pSortents,
                     UcDb::OpenMode openMode,
                     bool createIfNecessary=false);

    UcDbDatabase*     xrefDatabase(bool incUnres = false) const;

    bool              isUnloaded() const;
    Ucad::ErrorStatus setIsUnloaded(bool isUnloaded);

    UcDb::XrefStatus  xrefStatus() const;

    UcGiDrawable*     drawable();
    ZSoft::UInt32     setAttributes(UcGiDrawableTraits* pTraits);
    ZSoft::Boolean    worldDraw(UcGiWorldDraw* pWd);
    void              viewportDraw(UcGiViewportDraw* pVd);
    void              setGsNode(UcGsNode* pNode);
    UcGsNode*         gsNode() const;

    virtual Ucad::ErrorStatus decomposeForSave(UcDb::UcDbDwgVersion ver,
                                               UcDbObject*& replaceObj,
                                               UcDbObjectId& replaceId,
                                               ZSoft::Boolean& exchangeXData);
    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;

    virtual Ucad::ErrorStatus assumeOwnershipOf(UcArray <UcDbObjectId> entitiesToMove);

	enum BlockScaling {
		kAny,
		kUniform
	};

	UcDbBlockTableRecord::BlockScaling blockScaling () const;
    Ucad::ErrorStatus  setBlockScaling (
                        UcDbBlockTableRecord::BlockScaling blockScaling);

	Ucad::ErrorStatus setExplodable (bool bExplodable);
	bool              explodable () const;

	Ucad::ErrorStatus setBlockInsertUnits(UcDb::UnitsValue insunits);
	UcDb::UnitsValue blockInsertUnits() const;

    Ucad::ErrorStatus postProcessAnnotativeBTR(int& stripCnt, const bool bqueryOnly = false,
                                               const bool bScale = true);
	Ucad::ErrorStatus addAnnoScalestoBlkRefs(const bool bScale = false);

protected:
	virtual Ucad::ErrorStatus subGetClassID(CLSID* pClsid) const;
};

class UcDbLayerTableRecord: public  UcDbSymbolTableRecord
{
public:
    UCDB_DECLARE_MEMBERS(UcDbLayerTableRecord);

    UcDbLayerTableRecord();
    virtual ~UcDbLayerTableRecord();

    typedef UcDbLayerTable TableType;

    bool              isFrozen() const;
    Ucad::ErrorStatus setIsFrozen(bool frozen);

    bool              isOff() const;
    void              setIsOff(bool off);

    bool              VPDFLT() const;
    void              setVPDFLT(bool frozen);

    bool              isLocked() const;
    void              setIsLocked(bool locked);

    UcCmColor         color() const;
    void              setColor(const UcCmColor &color);
    UcCmEntityColor   entityColor(void) const;

    UcCmTransparency  transparency(void) const;
    Ucad::ErrorStatus setTransparency(const UcCmTransparency& trans);

    UcDbObjectId      linetypeObjectId() const;
    void              setLinetypeObjectId(UcDbObjectId id);

    UcDbObjectId      materialId() const;
    Ucad::ErrorStatus setMaterialId(UcDbObjectId id);

    enum { kDxfLayerPlotBit = UcDb::kDxfBool };
    bool              isPlottable() const;
    Ucad::ErrorStatus setIsPlottable(bool plot);

    UcDb::LineWeight  lineWeight() const;
    Ucad::ErrorStatus setLineWeight(UcDb::LineWeight weight);

    ZTCHAR*            plotStyleName() const;
    UcDbObjectId      plotStyleNameId() const;
    Ucad::ErrorStatus setPlotStyleName(const ZTCHAR* newName);
    Ucad::ErrorStatus setPlotStyleName(const UcDbObjectId& newId);

    UcGiDrawable*     drawable();
    ZSoft::UInt32     setAttributes(UcGiDrawableTraits* pTraits);
    ZSoft::Boolean    worldDraw(UcGiWorldDraw* pWd);
    void              viewportDraw(UcGiViewportDraw* pVd);
    void              setGsNode(UcGsNode* pNode);
    UcGsNode*         gsNode() const;

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;

    bool              isInUse() const;
    ZTCHAR*            description() const;
    Ucad::ErrorStatus setDescription(const ZTCHAR* description);

    bool              isHidden() const;
    Ucad::ErrorStatus setIsHidden(bool on);
    static bool isHidden(UcDbObjectId);
    UcCmColor         color(const UcDbObjectId& viewportId, bool& isOverride) const;
    Ucad::ErrorStatus setColor(const UcCmColor& color, 
                               const UcDbObjectId& viewportId);

    UcDbObjectId      linetypeObjectId(const UcDbObjectId& viewportId, bool& isOverride) const;
    Ucad::ErrorStatus setLinetypeObjectId(const UcDbObjectId& id, 
                                          const UcDbObjectId& viewportId);

    UcDb::LineWeight  lineWeight(const UcDbObjectId& viewportId, bool& isOverride) const;
    Ucad::ErrorStatus setLineWeight(UcDb::LineWeight weight, 
                                    const UcDbObjectId& viewportId);

    ZTCHAR*            plotStyleName(const UcDbObjectId& viewportId, bool& isOverride) const;
    UcDbObjectId      plotStyleNameId(const UcDbObjectId& viewportId, bool& isOverride) const;
    Ucad::ErrorStatus setPlotStyleName(const ZTCHAR* newName,
                                       const UcDbObjectId& viewportId);
    Ucad::ErrorStatus setPlotStyleName(const UcDbObjectId& newId, 
                                       const UcDbObjectId& viewportId);

    Ucad::ErrorStatus removeColorOverride(const UcDbObjectId& viewportId);
    Ucad::ErrorStatus removeLinetypeOverride(const UcDbObjectId& viewportId);
    Ucad::ErrorStatus removeLineWeightOverride(const UcDbObjectId& viewportId);
    Ucad::ErrorStatus removePlotStyleOverride(const UcDbObjectId& viewportId);
    Ucad::ErrorStatus removeViewportOverrides(const UcDbObjectId& viewportId);
    Ucad::ErrorStatus removeAllOverrides();

    bool              hasOverrides(const UcDbObjectId& viewportId) const;
    bool              hasAnyOverrides() const;

    bool              isReconciled() const;
    Ucad::ErrorStatus setIsReconciled(bool bReconcile = true);
    static bool       isReconciled(const UcDbObjectId& id);
};

Ucad::ErrorStatus applyCurDwgLayerTableChanges();

class UcDbTextStyleTableRecord: public  UcDbSymbolTableRecord
{
public:
    UCDB_DECLARE_MEMBERS(UcDbTextStyleTableRecord);

    UcDbTextStyleTableRecord();
    virtual ~UcDbTextStyleTableRecord();

    typedef UcDbTextStyleTable TableType;

    ZSoft::Boolean isShapeFile() const;
    void setIsShapeFile(ZSoft::Boolean shape);

    ZSoft::Boolean isVertical() const;
    void setIsVertical(ZSoft::Boolean vertical);

    double textSize() const;
    Ucad::ErrorStatus setTextSize(double size);

    double xScale() const;
    Ucad::ErrorStatus setXScale(double xScale);

    double obliquingAngle() const;
    Ucad::ErrorStatus setObliquingAngle(double obliquingAngle);

    ZSoft::UInt8 flagBits() const;
    void setFlagBits(ZSoft::UInt8 flagBits);

    double priorSize() const;
    Ucad::ErrorStatus setPriorSize(double priorSize);

    Ucad::ErrorStatus fileName(ZTCHAR*& fileName) const;
    Ucad::ErrorStatus fileName(const ZTCHAR*& fileName) const;
    Ucad::ErrorStatus setFileName(const ZTCHAR* fileName);

    Ucad::ErrorStatus bigFontFileName(ZTCHAR*& fileName) const;
    Ucad::ErrorStatus bigFontFileName(const ZTCHAR*& fileName) const;
    Ucad::ErrorStatus setBigFontFileName(const ZTCHAR* fileName);

    Ucad::ErrorStatus setFont(const ZTCHAR* pTypeface, ZSoft::Boolean bold,
        ZSoft::Boolean italic, int charset, int pitchAndFamily);
    Ucad::ErrorStatus font   (ZTCHAR*& pTypeface, ZSoft::Boolean& bold, ZSoft::Boolean& italic,
                              int& charset, int& pitchAndFamily) const;
    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
};

class UcDbLinetypeTableRecord: public  UcDbSymbolTableRecord
{
public:
    UCDB_DECLARE_MEMBERS(UcDbLinetypeTableRecord);

    UcDbLinetypeTableRecord();
    virtual ~UcDbLinetypeTableRecord();

    typedef UcDbLinetypeTable TableType;

    Ucad::ErrorStatus comments(ZTCHAR*& pString) const;
    Ucad::ErrorStatus comments(const ZTCHAR*& pString) const;
    Ucad::ErrorStatus setComments(const ZTCHAR* pString);

    Ucad::ErrorStatus asciiDescription(ZTCHAR*& pString) const
                      { return comments(pString); }
    Ucad::ErrorStatus asciiDescription(const ZTCHAR*& pString) const
                      { return comments(pString); }
    Ucad::ErrorStatus setAsciiDescription(const ZTCHAR* pString)
                      { return setComments(pString); }

    double patternLength() const;
    void   setPatternLength(double patternLength);

    int    numDashes() const;
    void   setNumDashes(int count);

    double dashLengthAt(int index) const;
    void   setDashLengthAt(int index , double value);

    UcDbObjectId shapeStyleAt(int index) const;
    void         setShapeStyleAt(int index, UcDbObjectId id);

    int    shapeNumberAt(int index) const;
    void   setShapeNumberAt(int index, int shapeNumber);

    UcGeVector2d shapeOffsetAt(int index) const;
    void         setShapeOffsetAt(int index, const UcGeVector2d& offset);

    double shapeScaleAt(int index) const;
    void   setShapeScaleAt(int index, double scale);

    bool isScaledToFit() const;
    void           setIsScaledToFit(bool scaledToFit);

    bool shapeIsUcsOrientedAt(int index) const;
    void           setShapeIsUcsOrientedAt(int index, bool isUcsOriented);

    double         shapeRotationAt(int index) const;
    void           setShapeRotationAt(int index, double rotation);

    Ucad::ErrorStatus textAt(int index, ZTCHAR*& text) const;
    Ucad::ErrorStatus textAt(int index, const ZTCHAR*& text) const;
    Ucad::ErrorStatus setTextAt(int index, const ZTCHAR* text);

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
    UcGiDrawable*     drawable();
    ZSoft::UInt32     setAttributes(UcGiDrawableTraits* pTraits);
    ZSoft::Boolean    worldDraw(UcGiWorldDraw* pWd);
    void              viewportDraw(UcGiViewportDraw* pVd);
    void              setGsNode(UcGsNode* pNode);
    UcGsNode*         gsNode() const;
};

class ZSOFT_NO_VTABLE UcDbAbstractViewTableRecord: public  UcDbSymbolTableRecord
{
public:
    UCDB_DECLARE_MEMBERS(UcDbAbstractViewTableRecord);

    UcDbAbstractViewTableRecord();
    virtual ~UcDbAbstractViewTableRecord();

    enum RenderMode {
        k2DOptimized,
        kWireframe,
        kHiddenLine,
        kFlatShaded,
        kGouraudShaded,
        kFlatShadedWithWireframe,
        kGouraudShadedWithWireframe
    };

    UcGePoint2d    centerPoint() const;
    void           setCenterPoint(const UcGePoint2d&);

    double         height() const;
    void           setHeight(double height);

    double         width() const;
    void           setWidth(double width);

    UcGePoint3d    target() const;
    void           setTarget(const UcGePoint3d& target);

    UcGeVector3d   viewDirection() const;
    void           setViewDirection(const UcGeVector3d& viewDirection);

    double         viewTwist() const;
    void           setViewTwist(double angle);

    double         lensLength() const;
    void           setLensLength(double length);

    double         frontClipDistance() const;
    void           setFrontClipDistance(double distance);

    double         backClipDistance() const;
    void           setBackClipDistance(double distance);

    bool           perspectiveEnabled() const;
    void           setPerspectiveEnabled(bool enabled);

    bool           frontClipEnabled() const;
    void           setFrontClipEnabled(bool enabled);

    bool           backClipEnabled() const;
    void           setBackClipEnabled(bool enabled);

    bool           frontClipAtEye() const;
    void           setFrontClipAtEye(bool atEye);

    void           setRenderMode(RenderMode mode);
    RenderMode     renderMode() const;
    const UcDbObjectId&  background() const;
    UcDbObjectId&       background();
    Ucad::ErrorStatus   setBackground(const UcDbObjectId& backgroundId);
    UcDbObjectId visualStyle() const;
    Ucad::ErrorStatus   setVisualStyle(const UcDbObjectId& visualStyleId);
    bool                isDefaultLightingOn() const;
    Ucad::ErrorStatus   setDefaultLightingOn(bool on);
    UcGiViewportTraits::DefaultLightingType defaultLightingType() const;
    Ucad::ErrorStatus   setDefaultLightingType(UcGiViewportTraits::DefaultLightingType typ);
    double              brightness() const;
    Ucad::ErrorStatus   setBrightness(double);

    double              contrast() const;
    Ucad::ErrorStatus   setContrast(double);

    UcCmColor           ambientLightColor() const;
    Ucad::ErrorStatus   setAmbientLightColor(const UcCmColor& clr);
    UcDbObjectId        sunId() const;
    Ucad::ErrorStatus   setSun(UcDbObjectId& retId, UcDbObject* pSun);
    Ucad::ErrorStatus toneOperatorParameters(UcGiToneOperatorParameters& params) const;
    Ucad::ErrorStatus setToneOperatorParameters(const UcGiToneOperatorParameters& params);
    Ucad::ErrorStatus getUcs            ( UcGePoint3d& origin,
                                          UcGeVector3d& xAxis,
                                          UcGeVector3d& yAxis ) const;
    bool              isUcsOrthographic ( UcDb::OrthographicView& view ) const;
    UcDbObjectId      ucsName           () const;
    double            elevation         () const;

    Ucad::ErrorStatus setUcs        ( const UcGePoint3d& origin,
                                      const UcGeVector3d& xAxis,
                                      const UcGeVector3d& yAxis );
    Ucad::ErrorStatus setUcs        ( UcDb::OrthographicView view );
    Ucad::ErrorStatus setUcs        ( const UcDbObjectId& ucsId );
    Ucad::ErrorStatus setUcsToWorld ();
    Ucad::ErrorStatus setElevation  ( double elev );

    bool              isViewOrthographic ( UcDb::OrthographicView& view ) const;
    Ucad::ErrorStatus setViewDirection   ( UcDb::OrthographicView view );
};

class UcDbViewTableRecord: public  UcDbAbstractViewTableRecord
{
public:
    UCDB_DECLARE_MEMBERS(UcDbViewTableRecord);

    UcDbViewTableRecord();
    virtual ~UcDbViewTableRecord();

    typedef UcDbViewTable TableType;

    Ucad::ErrorStatus setParametersFromViewport(UcDbObjectId objId);

    bool isPaperspaceView() const;
    void setIsPaperspaceView(bool pspace);
    
    bool    isUcsAssociatedToView   () const;
    Ucad::ErrorStatus disassociateUcsFromView ();

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;

    Ucad::ErrorStatus getCategoryName(ZTCHAR *& categoryName) const;
    Ucad::ErrorStatus setCategoryName(const ZTCHAR * categoryName);

    Ucad::ErrorStatus getLayerState(ZTCHAR*& layerStateName) const;
    Ucad::ErrorStatus setLayerState(const ZTCHAR *layerStateName);
 
    Ucad::ErrorStatus getLayout (UcDbObjectId& layoutId) const;
    Ucad::ErrorStatus setLayout(UcDbObjectId layoutId);

    bool              isViewAssociatedToViewport () const;
    Ucad::ErrorStatus setViewAssociatedToViewport (bool bVPflag);

    bool              isCameraPlottable () const;
    Ucad::ErrorStatus setIsCameraPlottable (bool plottable);
    UcDbObjectId      liveSection() const;
    Ucad::ErrorStatus setLiveSection(const UcDbObjectId& liveSectionId);

#ifdef _WINDOWS_
    Ucad::ErrorStatus getThumbnail (BITMAPINFO*& thumbnail) const;
    Ucad::ErrorStatus setThumbnail(const BITMAPINFO * thumbnail);
#endif
    UcDbObjectId      camera          () const;
    Ucad::ErrorStatus setCamera(UcDbObjectId cameraId);
    UcDbAnnotationScale* annotationScale() const;
    Ucad::ErrorStatus setAnnotationScale(const UcDbAnnotationScale* pScaleObj);
    UcDbObjectId      sunId() const;
    Ucad::ErrorStatus setSun(UcDbObjectId& retId, UcDbObject* pSun);
};

class UcDbUCSTableRecord: public  UcDbSymbolTableRecord
{
public:
    UCDB_DECLARE_MEMBERS(UcDbUCSTableRecord);

    UcDbUCSTableRecord();
    virtual ~UcDbUCSTableRecord();

    typedef UcDbUCSTable TableType;

    UcGePoint3d  origin() const;
    void         setOrigin(const UcGePoint3d& newOrigin);

    UcGeVector3d xAxis() const;
    void         setXAxis(const UcGeVector3d& xAxis);

    UcGeVector3d yAxis() const;
    void         setYAxis(const UcGeVector3d& yAxis);

    UcGePoint3d       ucsBaseOrigin    ( UcDb::OrthographicView view ) const;
    Ucad::ErrorStatus setUcsBaseOrigin ( const UcGePoint3d& origin,
                                         UcDb::OrthographicView view );
    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
};

class UcDbViewportTableRecord: public  UcDbAbstractViewTableRecord
{
public:
    UCDB_DECLARE_MEMBERS(UcDbViewportTableRecord);

    UcDbViewportTableRecord();
    virtual ~UcDbViewportTableRecord();

    typedef UcDbViewportTable TableType;

    ZSoft::Int16   number()  const;

    UcGePoint2d    lowerLeftCorner() const;
    void           setLowerLeftCorner(const UcGePoint2d& pt);

    UcGePoint2d    upperRightCorner() const;
    void           setUpperRightCorner(const UcGePoint2d& pt);

    bool           ucsFollowMode() const;
    void           setUcsFollowMode(bool enabled);

    ZSoft::UInt16  circleSides() const;
    void           setCircleSides(ZSoft::UInt16 circleSides);

	bool           fastZoomsEnabled() const { return true; }
	void           setFastZoomsEnabled(bool enabled) { }

    bool           iconEnabled() const;
    void           setIconEnabled(bool enabled);

    bool           iconAtOrigin() const;
    void           setIconAtOrigin(bool atOrigin);

    bool           gridEnabled() const;
    void           setGridEnabled(bool enabled);

    UcGePoint2d    gridIncrements() const;
    void           setGridIncrements(const UcGePoint2d& base);

    bool           snapEnabled() const;
    void           setSnapEnabled(bool enabled);

    bool           isometricSnapEnabled() const;
    void           setIsometricSnapEnabled(bool enabled);

    ZSoft::Int16   snapPair() const;
    void           setSnapPair(ZSoft::Int16 pairType);

    double         snapAngle() const;
    void           setSnapAngle(double angle);

    UcGePoint2d    snapBase() const;
    void           setSnapBase(const UcGePoint2d& base);

    UcGePoint2d    snapIncrements() const;
    void           setSnapIncrements(const UcGePoint2d& base);

    void           setGsView(UcGsView* pView);
    UcGsView*      gsView() const;

    bool           isUcsSavedWithViewport () const;
    void           setUcsPerViewport ( bool ucsvp );
    bool           isGridBoundToLimits() const;
    void           setGridBoundToLimits(bool enabled);

    bool           isGridAdaptive() const;
    void           setGridAdaptive(bool enabled);

    bool           isGridSubdivisionRestricted() const;
    void           setGridSubdivisionRestricted(bool enabled);

    bool           isGridFollow() const;
    void           setGridFollow(bool enabled);

    ZSoft::Int16   gridMajor() const;
    void           setGridMajor(ZSoft::Int16 value);
    Ucad::ErrorStatus   setBackground(const UcDbObjectId& backgroundId);
    UcDbObjectId        previousBackground(UcGiDrawable::DrawableType type
                                           = UcGiDrawable::kGeometry) const;
    Ucad::ErrorStatus   setPreviousBackground(UcDbObjectId backgroundId,
                                              UcGiDrawable::DrawableType type
                                              = UcGiDrawable::kGeometry);
    UcGiDrawable*  drawable();
    ZSoft::UInt32  setAttributes(UcGiDrawableTraits* pTraits);
    ZSoft::Boolean worldDraw(UcGiWorldDraw* pWd);     
    void           setGsNode(UcGsNode* pNode);
    UcGsNode*      gsNode() const;

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
};

class UcDbRegAppTableRecord: public  UcDbSymbolTableRecord
{
public:
    UCDB_DECLARE_MEMBERS(UcDbRegAppTableRecord);

    UcDbRegAppTableRecord();
    virtual ~UcDbRegAppTableRecord();

    typedef UcDbRegAppTable TableType;

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
};

class UcDbDimStyleTableRecord: public  UcDbSymbolTableRecord
{
public:
    UCDB_DECLARE_MEMBERS(UcDbDimStyleTableRecord);

    UcDbDimStyleTableRecord();
    virtual ~UcDbDimStyleTableRecord();

    typedef UcDbDimStyleTable TableType;

    #undef UDBDIMVAR_H         
    #include "zdbdimvar.h"

    UcDbObjectId      arrowId(UcDb::DimArrowFlags whichArrow) const;

    Ucad::ErrorStatus getDimpost(ZTCHAR*& pOutput) const;
    Ucad::ErrorStatus getDimapost(ZTCHAR*& pOutput) const;
    Ucad::ErrorStatus getDimblk(ZTCHAR*& pOutput) const;
    Ucad::ErrorStatus getDimblk1(ZTCHAR*& pOutput) const;
    Ucad::ErrorStatus getDimblk2(ZTCHAR*& pOutput) const;

    int dimfit() const;
    int dimunit() const;

    Ucad::ErrorStatus setDimfit(int fit);
    Ucad::ErrorStatus setDimunit(int unit);

    virtual Ucad::ErrorStatus getClassID(CLSID* pClsid) const;
    bool isModifiedForRecompute() const;    
};

#pragma pack(pop)

#endif
